﻿using com.nm.ApiServer;
using com.nm.ApiServer.Attributes;
using com.nm.Attributes;
using george.Data;
using NHibernateVertica;
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq.Expressions;

namespace VerticaAPI
{
    [Description("返回门店信息")]
    public class BasShopHandler:BaseHandler
    {
        [MustLogin]
        [Description("获取门店列表")]
        [ReturnType(typeof(PaperData<model.BasShopModel>))]
        public ApiResult GetList([ParamDescription("页码")]int Page, [ParamDescription("页数")]int Size,[ParamDescription("地区ID")]string areaId = "")
        {
            Expression<Func<model.BasShopModel, bool>> whereLambda = t => true;
            if (!string.IsNullOrEmpty(areaId))
            {
                whereLambda = t => t.AreaID == areaId;
            }
            Expression<Func<model.BasShopModel, string>> orderBy = t => t.ShopID;
            var result = VerticaDBHelper.ReadByPage<model.BasShopModel, string>(Page, Size, whereLambda, orderBy);
            return Success(result);
        }

        public ApiResult ImportExcel()
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();
            var dt = VerticaDBHelper.ExcelToDataTable<model.BasShopModel>("D:\\123\\test.xlsx", false);

            var a = VerticaDBHelper.BulkCopy<model.BasShopModel>(dt, "ods.dim_Bas_Shop");
            watch.Stop();
            string time = watch.ElapsedMilliseconds.ToString();
            if (a == 0)
            {
                return Success(time);
            }
            else return Error("Excel 上传失败！");
        }
    }
}
